﻿/*
 * 作者：DHclly
 * 描述：此例子演示通过编写一个热水机，随着温度上升，触发相关事件。
 *       演示事件的声明，事件参数构建，事件订阅/通知
 */
using System;

namespace IceDog.Lib.Event.BoildWater
{
    /// <summary>
    /// 热水器类
    /// </summary>
    public sealed class Heater
    {
        private int _temperature;
        private string _type = "国美";
        private string _area = "中国";
        /// <summary>
        /// 品牌
        /// </summary>
        public string Type
        {
            get { return _type; }
        }
        /// <summary>
        /// 出产地
        /// </summary>
        public string Area
        {
            get { return _area; }
        }
        /// <summary>
        /// 声明加热事件处理委托
        /// </summary>
        /// <param name="sender">事件发起者</param>
        /// <param name="args">事件参数</param>
        public delegate void BoiledEventHandler(Object sender, BoiledEventArgs args);
        /// <summary>
        /// 声明加热事件
        /// </summary>
        public event BoiledEventHandler Boiled;
        /// <summary>
        /// 在加热过程中执行的委托方法
        /// </summary>
        /// <param name="args"></param>
        private void OnBoiled(BoiledEventArgs args)
        {
            var handler = Boiled;
            if (handler != null)
                handler(this, args);
        }
        /// <summary>
        /// 进行热水
        /// </summary>
        public void BoilWater()
        {
            for (int i = 0; i <=100; i++)
            {
                _temperature = i;
                if (_temperature>95)
                {
                    BoiledEventArgs eventArgs = new BoiledEventArgs(_temperature);
                    OnBoiled(eventArgs);
                }
            }
        }
    }
}
